package com.cq.jackmar.rxdemo.demo;

import android.animation.ValueAnimator;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cq.jackmar.rxdemo.R;
import com.cq.jackmar.rxdemo.util.Rotate3dAnimation;
import com.cq.jackmar.rxdemo.base.BaseActivity;
import com.cq.jackmar.rxdemo.util.ViewUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by JackMar on 2017/3/3.
 * 邮箱：1261404794@qq.com
 */

public class AnimationActivity extends BaseActivity {
    @Bind(R.id.tv_text)
    TextView mTvText;
    @Bind(R.id.iv_image)
    ImageView mIvImage;
    @Bind(R.id.ll_content)
    LinearLayout mLlContent;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_animation;
    }

    @Override
    protected void initView() {
        Rotate3dAnimation rotation = new Rotate3dAnimation(0, 360, ViewUtil.dip2px(context, 50), ViewUtil.dip2px(context, 50),
                0, false);
        // 动画持续时间500毫秒
        rotation.setDuration(2000);
        // 动画完成后保持完成的状态
        rotation.setFillAfter(true);
        rotation.setInterpolator(new LinearInterpolator());
        rotation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                Log.e("onAnimationEnd: ", "onAnimationEnd: 完成");
                mLlContent.setVisibility(View.GONE);
                mTvText.setVisibility(View.VISIBLE);
                ValueAnimator animator = ValueAnimator.ofFloat(1.8f, 1.2f, 1.5f, 0.8f);
                animator.setDuration(1500);
                animation.setFillAfter(false);
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        float curValue = (float) animation.getAnimatedValue();
                        Log.e("onAnimationUpdate: ", "onAnimationUpdate: " + curValue);
//                        mTvText.setTextSize(30 * (1 + curValue));
                    }
                });
                animator.start();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        mIvImage.startAnimation(rotation);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
